//index.js
import api from '../../tool/requestModel.js'
import getUserInfo from '../../getUserInfo.js'
const app = getApp()
Page({
    onShareAppMessage(shareInfo){
        const { from } = shareInfo;
        return {
            imageUrl: '',
            title: '更多有趣测试等你来测！',
            path: 'pages/index/index?share_user_id='+tt.getStorageSync("userId"),
        }
    },
	data: {
		indexDetail: {},
		iconList: [],
		remDetail: "热门题目",
		ggd: '更多测试',
		dizhi: 'https://t.doule.shop/',
		kefuShow:false,
        height:"",
        num:'0',
        left:'0',
        bind_promote:"",
        versionNumber:true,
        boxList:[]
	},
    onReady:function(){
        
        this.setData({
            bind_promote:tt.getStorageSync('bind_promote')
        })
    },
	onLoad: function(option) {
        if(option.share_user_id){
            tt.setStorage({
                data: option.share_user_id,
                key: 'share_user_id',
            })
        }
        let that = this
        setTimeout(function(){
            that.setData({
                bind_promote:tt.getStorageSync('bind_promote'),
                versionNumber:app.globalData.versionNumber
            })
        },1000)
        app.globalData.show=false
		this.list()
	},
    list :function(){
        api.pingCeIndex()
			.then(res => {
                console.log(res.data.tuijian1[0])
				this.setData({
                    indexDetail:res.data,
					iconList:res.data.Product_Category
				})
                this.setData({
					boxList:res.data.tuijian1[0]
				})
                console.log(this.data.boxList)
			})
            
    },
	searchBtn:function() {
		tt.navigateTo({
			url: '../search/search',
		})
	},
    getPhoneNummer:function(e){
        this.setData({
            code:e.detail.value
        })
    },
    bangding:function(){
        this.setData({
                kefuShow:true
            })
    },
    ok:function(){
        let openId = tt.getStorageSync('option_id')
        if(!tt.getStorageSync('userName')){
            getUserInfo(openId)
        }
        let that = this
        setTimeout(function(){
            api.bind_promote({"user_id":tt.getStorageSync('userId'),"bind_code":that.data.code})
                .then(res => {
                    console.log(res)
                    if(res.code==200){
                        tt.setStorageSync('bind_promote', '1')
                        that.setData({
                            kefuShow:false,
                            bind_promote:1
                        })
                    }else{
                        tt.showToast({
                            title: res.msg,
                            duration: 1500,
                            icon: "none"
                        })
                    }

                }) 
        },500)
    },
    fanhui:function(e){
        if(e.currentTarget.dataset.index==1){
            this.setData({
                left:'-300'
            })
        }else{
            this.setData({
                left:'0'
            })
        }
        this.setData({
            num:e.currentTarget.dataset.index
        })
    },
	lbxq:function(e) {
		// console.log(item)
		let item = e.currentTarget.dataset.item
		tt.navigateTo({
			url: '../liebiao/liebiao?id=' + item
		})
	},
	imgPage:function(){
		tt.navigateTo({
			url: '../img/img'
		})
	},
	musicPage:function() {
		tt.navigateTo({
			url: '../music/music'
		})
	},
	backZhe:function(){
		this.setData({
			kefuShow:!this.data.kefuShow
		})
	},
	save:function(){
		tt.saveImageToPhotosAlbum({
			filePath: '/static/kefu.png',
			success: resp => {
				tt.showToast({
					title: "保存成功",
					icon: "none"
				});
			},
			fail: function(err) {
				console.log(err)
			}
		});
	},
	dingdan:function(){
		tt.navigateTo({
			url: '../myOrder/myOrder'
		})
	},
    history:function(){ 
        tt.navigateTo({
            url:"../history/history"
        })
    },
    onShow(option){
        console.log(app.globalData.bind_promote)
        app.globalData.show=false
        this.setData({
            bind_promote:tt.getStorageSync('bind_promote'),
            versionNumber:app.globalData.versionNumber
        })
    },
})
